package com.gexiaobao.pigeon.ui.breeding_pigeon

import android.annotation.SuppressLint
import android.graphics.Bitmap
import android.os.Bundle
import android.widget.ImageView
import androidx.appcompat.widget.AppCompatImageView
import androidx.core.view.isVisible
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.LinearLayoutManager
import com.flyjingfish.openimagelib.OpenImage
import com.flyjingfish.openimagelib.enums.MediaType
import com.gexiaobao.pigeon.R
import com.gexiaobao.pigeon.app.base.BaseActivity
import com.gexiaobao.pigeon.app.eventViewModel
import com.gexiaobao.pigeon.app.ext.Constant
import com.gexiaobao.pigeon.app.ext.init
import com.gexiaobao.pigeon.app.ext.showMessage
import com.gexiaobao.pigeon.app.model.bean.BloodBookDetailResponse
import com.gexiaobao.pigeon.app.model.bean.EditBloodInfoBean
import com.gexiaobao.pigeon.app.util.ImageLoaderManager
import com.gexiaobao.pigeon.app.util.ImgUtils
import com.gexiaobao.pigeon.app.util.PictureUtil
import com.gexiaobao.pigeon.app.util.RxToast
import com.gexiaobao.pigeon.app.util.StatusBarUtil
import com.gexiaobao.pigeon.app.util.Util
import com.gexiaobao.pigeon.app.util.WxShareUtils
import com.gexiaobao.pigeon.app.weight.recycleview.SpaceItemDecoration
import com.gexiaobao.pigeon.databinding.ActivityPedigreeStyleInfoBinding
import com.gexiaobao.pigeon.permissions.PermissionInterceptor
import com.gexiaobao.pigeon.ui.adapter.AdapterFive1Style
import com.gexiaobao.pigeon.ui.adapter.AdapterFive2Style
import com.gexiaobao.pigeon.ui.adapter.AdapterFive3Style
import com.gexiaobao.pigeon.ui.adapter.AdapterFive4Style
import com.gexiaobao.pigeon.ui.adapter.AdapterFour1Style
import com.gexiaobao.pigeon.ui.adapter.AdapterFour2Style
import com.gexiaobao.pigeon.ui.adapter.AdapterFour3Style
import com.gexiaobao.pigeon.ui.adapter.AdapterFour4Style
import com.gexiaobao.pigeon.ui.adapter.AdapterFourV1Style
import com.gexiaobao.pigeon.ui.adapter.AdapterFourV2Style
import com.gexiaobao.pigeon.ui.adapter.AdapterFourV3Style
import com.gexiaobao.pigeon.ui.adapter.AdapterFourV4Style
import com.gexiaobao.pigeon.ui.adapter.AdapterThree1Style
import com.gexiaobao.pigeon.ui.adapter.AdapterThree2Style
import com.gexiaobao.pigeon.ui.adapter.AdapterThree3Style
import com.gexiaobao.pigeon.ui.dialog.BottomSharePictureDialog
import com.gexiaobao.pigeon.ui.dialog.RxDialogDefault
import com.gexiaobao.pigeon.viewmodel.BreedingPigeonViewModel
import com.gexiaobao.xpopup.util.PermissionConstants
import com.gexiaobao.xpopup.util.XPermission
import com.google.gson.Gson
import com.hjq.permissions.OnPermissionCallback
import com.hjq.permissions.Permission
import com.hjq.permissions.XXPermissions
import me.hgj.jetpackmvvm.ext.util.setOnclickNoRepeat
import me.hgj.jetpackmvvm.util.LogUtils
import me.hgj.jetpackmvvm.util.startActivity
import okhttp3.MediaType.Companion.toMediaTypeOrNull
import okhttp3.RequestBody
import okhttp3.RequestBody.Companion.toRequestBody
import java.io.File

/**
 * @Author      : hxw
 * @Date        : 2024/9/20 17:45
 * @Describe    : 选择风格样式
 */
class ActivityPedigreeStyleInfo : BaseActivity<BreedingPigeonViewModel, ActivityPedigreeStyleInfoBinding>() {

    private var fourV4height: Int = 0
    private val mAdapter1: AdapterThree1Style by lazy { AdapterThree1Style(arrayListOf()) }
    private val mList1: ArrayList<EditBloodInfoBean> = arrayListOf()

    private val mAdapter2: AdapterThree2Style by lazy { AdapterThree2Style(arrayListOf()) }
    private val mList2: ArrayList<EditBloodInfoBean> = arrayListOf()

    private val mAdapter3: AdapterThree3Style by lazy { AdapterThree3Style(arrayListOf()) }
    private val mList3: ArrayList<EditBloodInfoBean> = arrayListOf()

    private val mAdapterFour1: AdapterFour1Style by lazy { AdapterFour1Style(arrayListOf()) }
    private val mListFour1: ArrayList<EditBloodInfoBean> = arrayListOf()

    private val mAdapterFour2: AdapterFour2Style by lazy { AdapterFour2Style(arrayListOf()) }
    private val mListFour2: ArrayList<EditBloodInfoBean> = arrayListOf()

    private val mAdapterFour3: AdapterFour3Style by lazy { AdapterFour3Style(arrayListOf()) }
    private val mListFour3: ArrayList<EditBloodInfoBean> = arrayListOf()

    private val mAdapterFour4: AdapterFour4Style by lazy { AdapterFour4Style(arrayListOf()) }
    private val mListFour4: ArrayList<EditBloodInfoBean> = arrayListOf()

    private val mAdapterFourV1: AdapterFourV1Style by lazy { AdapterFourV1Style(arrayListOf()) }
    private val mListFourV1: ArrayList<EditBloodInfoBean> = arrayListOf()

    private val mAdapterFourV2: AdapterFourV2Style by lazy { AdapterFourV2Style(arrayListOf()) }
    private val mListFourV2: ArrayList<EditBloodInfoBean> = arrayListOf()

    private val mAdapterFourV3: AdapterFourV3Style by lazy { AdapterFourV3Style(arrayListOf()) }
    private val mListFourV3: ArrayList<EditBloodInfoBean> = arrayListOf()

    private val mAdapterFourV4: AdapterFourV4Style by lazy { AdapterFourV4Style(arrayListOf()) }
    private val mListFourV4: ArrayList<EditBloodInfoBean> = arrayListOf()

    private val mAdapterFive1: AdapterFive1Style by lazy { AdapterFive1Style(arrayListOf()) }
    private val mListFive1: ArrayList<EditBloodInfoBean> = arrayListOf()

    private val mAdapterFive2: AdapterFive2Style by lazy { AdapterFive2Style(arrayListOf()) }
    private val mListFive2: ArrayList<EditBloodInfoBean> = arrayListOf()

    private val mAdapterFive3: AdapterFive3Style by lazy { AdapterFive3Style(arrayListOf()) }
    private val mListFive3: ArrayList<EditBloodInfoBean> = arrayListOf()

    private val mAdapterFive4: AdapterFive4Style by lazy { AdapterFive4Style(arrayListOf()) }
    private val mListFive4: ArrayList<EditBloodInfoBean> = arrayListOf()

    private var typeGeneration = ""
    private var bigImageUrl = ""
    private var mId = 0

    override fun initView(savedInstanceState: Bundle?) {
        StatusBarUtil.setTranslucentForImageView(this, 0, null)
        mDatabind.includeBar.tvTitle.text = getString(R.string.choose_style)
        mDatabind.includeBar.tvRightMenu.text = getString(R.string.share)
        mDatabind.includeBar.tvRightMenu.isVisible = true

        mId = intent.getIntExtra("id", 0)

        mDatabind.includeBtn.tvLeftBtn.text = getString(R.string.edit_information)
        mDatabind.includeBtn.tvRightBtn.text = "保存图片并下载"

        typeGeneration = intent.getStringExtra("typeGeneration").toString()
        val mInfoDetail = intent.getParcelableExtra<BloodBookDetailResponse>("dataBean")!!
        initAdapters()
        initData()
        echoData(mInfoDetail)

        onRefresh()

        eventViewModel.toRefreshData.observeInActivity(this) {
            onRefresh()
        }
    }

    private fun onRefresh() {
        showLoading(getString(R.string.loading))
        mViewModel.getBloodBookHouse(mId.toString())
    }

    @SuppressLint("SetTextI18n")
    override fun createObserver() {
        super.createObserver()
        /** 添加血统书图片 */
        mViewModel.addBloodImageResult.observe(this) {

        }
        /** 获取鸽舍信息 */
        mViewModel.getBloodBookHouseResult.observe(this) {
            when (typeGeneration) {
                "three" -> {
                    mDatabind.includeThree.includeThreeInfo.tvName.text = it.name
                    mDatabind.includeThree.includeThreeInfo.tvName.isVisible = it.nameStatus == 1
                    mDatabind.includeThree.includeThreeInfo.tvMobile.text = getString(R.string.telphone) + it.mobile
                    mDatabind.includeThree.includeThreeInfo.tvMobile.isVisible = it.mobileStatus == 1
                    mDatabind.includeThree.includeThreeInfo.tvEmail.text = getString(R.string.email) + it.email
                    mDatabind.includeThree.includeThreeInfo.tvEmail.isVisible = it.emailStatus == 1
                    mDatabind.includeThree.includeThreeInfo.tvAddress.text = getString(R.string.address) + ":" + it.address
                    mDatabind.includeThree.includeThreeInfo.tvAddress.isVisible = it.addressStatus == 1
                    mDatabind.includeThree.includeThreeInfo.tvKWai.text = getString(R.string.kWai) + it.kWai
                    mDatabind.includeThree.includeThreeInfo.tvKWai.isVisible = it.kWaiStatus == 1
                    mDatabind.includeThree.includeThreeInfo.tvTikTok.text = getString(R.string.tikTok) + it.tikTok
                    mDatabind.includeThree.includeThreeInfo.tvTikTok.isVisible = it.tikTokStatus == 1
                }

                "four" -> {
                    mDatabind.includeFour.includeFourInfo.tvName.text = it.name
                    mDatabind.includeFour.includeFourInfo.tvName.isVisible = it.nameStatus == 1
                    mDatabind.includeFour.includeFourInfo.tvMobile.text = getString(R.string.telphone) + it.mobile
                    mDatabind.includeFour.includeFourInfo.tvMobile.isVisible = it.mobileStatus == 1
                    mDatabind.includeFour.includeFourInfo.tvEmail.text = getString(R.string.email) + it.email
                    mDatabind.includeFour.includeFourInfo.tvEmail.isVisible = it.emailStatus == 1
                    mDatabind.includeFour.includeFourInfo.tvAddress.text = getString(R.string.address) + ":" + it.address
                    mDatabind.includeFour.includeFourInfo.tvAddress.isVisible = it.addressStatus == 1
                    mDatabind.includeFour.includeFourInfo.tvKWai.text = getString(R.string.kWai) + it.kWai
                    mDatabind.includeFour.includeFourInfo.tvKWai.isVisible = it.kWaiStatus == 1
                    mDatabind.includeFour.includeFourInfo.tvTikTok.text = getString(R.string.tikTok) + it.tikTok
                    mDatabind.includeFour.includeFourInfo.tvTikTok.isVisible = it.tikTokStatus == 1
                }

                "fourV" -> {
                    mDatabind.includeFourV.includeFourVInfo.tvName.text = it.name
                    mDatabind.includeFourV.includeFourVInfo.tvName.isVisible = it.nameStatus == 1
                    mDatabind.includeFourV.includeFourVInfo.tvMobile.text = getString(R.string.telphone) + it.mobile
                    mDatabind.includeFourV.includeFourVInfo.tvMobile.isVisible = it.mobileStatus == 1
                    mDatabind.includeFourV.includeFourVInfo.tvEmail.text = getString(R.string.email) + it.email
                    mDatabind.includeFourV.includeFourVInfo.tvEmail.isVisible = it.emailStatus == 1
                    mDatabind.includeFourV.includeFourVInfo.tvAddress.text = getString(R.string.address) + ":" + it.address
                    mDatabind.includeFourV.includeFourVInfo.tvAddress.isVisible = it.addressStatus == 1
                    mDatabind.includeFourV.includeFourVInfo.tvKWai.text = getString(R.string.kWai) + it.kWai
                    mDatabind.includeFourV.includeFourVInfo.tvKWai.isVisible = it.kWaiStatus == 1
                    mDatabind.includeFourV.includeFourVInfo.tvTikTok.text = getString(R.string.tikTok) + it.tikTok
                    mDatabind.includeFourV.includeFourVInfo.tvTikTok.isVisible = it.tikTokStatus == 1
                }

                else -> {
                    mDatabind.includeFive.includeFiveInfo.tvName.text = it.name
                    mDatabind.includeFive.includeFiveInfo.tvName.isVisible = it.nameStatus == 1
                    mDatabind.includeFive.includeFiveInfo.tvMobile.text = getString(R.string.telphone) + it.mobile
                    mDatabind.includeFive.includeFiveInfo.tvMobile.isVisible = it.mobileStatus == 1
                    mDatabind.includeFive.includeFiveInfo.tvEmail.text = getString(R.string.email) + it.email
                    mDatabind.includeFive.includeFiveInfo.tvEmail.isVisible = it.emailStatus == 1
                    mDatabind.includeFive.includeFiveInfo.tvAddress.text = getString(R.string.address) + ":" + it.address
                    mDatabind.includeFive.includeFiveInfo.tvAddress.isVisible = it.addressStatus == 1
                    mDatabind.includeFive.includeFiveInfo.tvKWai.text = getString(R.string.kWai) + it.kWai
                    mDatabind.includeFive.includeFiveInfo.tvKWai.isVisible = it.kWaiStatus == 1
                    mDatabind.includeFive.includeFiveInfo.tvTikTok.text = getString(R.string.tikTok) + it.tikTok
                    mDatabind.includeFive.includeFiveInfo.tvTikTok.isVisible = it.tikTokStatus == 1
                }
            }
        }
    }

    @SuppressLint("NotifyDataSetChanged")
    private fun initData() {
        mList1.add(EditBloodInfoBean())
        mAdapter1.setList(mList1)
        mAdapter1.notifyDataSetChanged()

        for (i in 0..1) {
            mList2.add(EditBloodInfoBean())
        }
        mAdapter2.setList(mList2)
        mAdapter2.notifyDataSetChanged()

        for (i in 0..3) {
            mList3.add(EditBloodInfoBean())
        }
        mAdapter3.setList(mList3)
        mAdapter3.notifyDataSetChanged()

        mListFour1.add(EditBloodInfoBean())
        mAdapterFour1.setList(mListFour1)
        mAdapterFour1.notifyDataSetChanged()

        for (i in 0..1) {
            mListFour2.add(EditBloodInfoBean())
        }
        mAdapterFour2.setList(mListFour2)
        mAdapterFour2.notifyDataSetChanged()

        for (i in 0..3) {
            mListFour3.add(EditBloodInfoBean())
        }
        mAdapterFour3.setList(mListFour3)
        mAdapterFour3.notifyDataSetChanged()

        for (i in 0..7) {
            mListFour4.add(EditBloodInfoBean())
        }
        mAdapterFour4.setList(mListFour4)
        mAdapterFour4.notifyDataSetChanged()

        mListFourV1.add(EditBloodInfoBean())
        mAdapterFourV1.setList(mListFourV1)
        mAdapterFourV1.notifyDataSetChanged()

        for (i in 0..1) {
            mListFourV2.add(EditBloodInfoBean())
        }
        mAdapterFourV2.setList(mListFourV2)
        mAdapterFourV2.notifyDataSetChanged()

        for (i in 0..3) {
            mListFourV3.add(EditBloodInfoBean())
        }
        mAdapterFourV3.setList(mListFourV3)
        mAdapterFourV3.notifyDataSetChanged()

        for (i in 0..7) {
            mListFourV4.add(EditBloodInfoBean())
        }
        mAdapterFourV4.setList(mListFourV4)
        mAdapterFourV4.notifyDataSetChanged()

        for (i in 0..2) {
            mListFive1.add(EditBloodInfoBean())
        }
        mAdapterFive1.setList(mListFive1)
        mAdapterFive1.notifyDataSetChanged()

        for (i in 0..3) {
            mListFive2.add(EditBloodInfoBean())
        }
        mAdapterFive2.setList(mListFive2)
        mAdapterFive2.notifyDataSetChanged()

        for (i in 0..7) {
            mListFive3.add(EditBloodInfoBean())
        }
        mAdapterFive3.setList(mListFive3)
        mAdapterFive3.notifyDataSetChanged()

        for (i in 0..15) {
            mListFive4.add(EditBloodInfoBean())
        }
        mAdapterFive4.setList(mListFive4)
        mAdapterFive4.notifyDataSetChanged()
    }

    override fun onResume() {
        super.onResume()
        mDatabind.includeFourV.llFourV4.post {
            fourV4height = mDatabind.includeFourV.llFourV4.height
            mAdapterFourV4.setLayoutHeight(fourV4height)
        }
    }

    private fun initAdapters() {
        mDatabind.includeThree.swipeRecyclerView1.init(LinearLayoutManager(this), mAdapter1)

        mDatabind.includeThree.swipeRecyclerView2.init(LinearLayoutManager(this), mAdapter2).addItemDecoration(
            SpaceItemDecoration(0, Util.dp2px(this, 8f))
        )

        mDatabind.includeThree.swipeRecyclerView3.init(LinearLayoutManager(this), mAdapter3).addItemDecoration(
            SpaceItemDecoration(0, Util.dp2px(this, 6f))
        )

        mDatabind.includeFour.swipeRecyclerView1.init(LinearLayoutManager(this), mAdapterFour1)

        mDatabind.includeFour.swipeRecyclerView2.init(LinearLayoutManager(this), mAdapterFour2).addItemDecoration(
            SpaceItemDecoration(0, Util.dp2px(this, 18f))
        )

        mDatabind.includeFour.swipeRecyclerView3.init(LinearLayoutManager(this), mAdapterFour3).addItemDecoration(
            SpaceItemDecoration(0, Util.dp2px(this, 4f))
        )

        mDatabind.includeFour.swipeRecyclerView4.init(LinearLayoutManager(this), mAdapterFour4).addItemDecoration(
            SpaceItemDecoration(0, Util.dp2px(this, 4f))
        )

        mDatabind.includeFourV.swipeRecyclerView1.init(LinearLayoutManager(this), mAdapterFourV1)

        mDatabind.includeFourV.swipeRecyclerView2.init(GridLayoutManager(this, 2), mAdapterFourV2).addItemDecoration(
            SpaceItemDecoration(Util.dp2px(this, 14f), 0)
        )

        mDatabind.includeFourV.swipeRecyclerView3.init(GridLayoutManager(this, 4), mAdapterFourV3).addItemDecoration(
            SpaceItemDecoration(Util.dp2px(this, 2f), 0)
        )

        mDatabind.includeFourV.swipeRecyclerView4.init(GridLayoutManager(this, 4), mAdapterFourV4).addItemDecoration(
            SpaceItemDecoration(Util.dp2px(this, 4f), 0)
        )

        mDatabind.includeFive.swipeRecyclerView1.init(LinearLayoutManager(this), mAdapterFive1).addItemDecoration(
            SpaceItemDecoration(0, Util.dp2px(this, 4f))
        )

        mDatabind.includeFive.swipeRecyclerView2.init(LinearLayoutManager(this), mAdapterFive2).addItemDecoration(
            SpaceItemDecoration(0, Util.dp2px(this, 4f))
        )

        mDatabind.includeFive.swipeRecyclerView3.init(LinearLayoutManager(this), mAdapterFive3).addItemDecoration(
            SpaceItemDecoration(0, Util.dp2px(this, 5f))
        )

        mDatabind.includeFive.swipeRecyclerView4.init(LinearLayoutManager(this), mAdapterFive4)
    }

    override fun onBindViewClick() {
        super.onBindViewClick()
        setOnclickNoRepeat(
            mDatabind.includeBar.ivBack,
            mDatabind.includeBtn.tvLeftBtn,
            mDatabind.includeBar.tvRightMenu,
            mDatabind.includeBtn.tvRightBtn,
            mDatabind.includeThree.ivThreeCoverImage,
            mDatabind.includeFour.ivFourCoverImage,
            mDatabind.includeFourV.ivFourVCoverImage,
            mDatabind.includeFive.ivFiveImageCover
        ) {
            when (it) {
                mDatabind.includeFive.ivFiveImageCover -> openBigImage(mDatabind.includeFive.ivFiveImageCover)
                mDatabind.includeFourV.ivFourVCoverImage -> openBigImage(mDatabind.includeFourV.ivFourVCoverImage)
                mDatabind.includeFour.ivFourCoverImage -> openBigImage(mDatabind.includeFour.ivFourCoverImage)
                mDatabind.includeThree.ivThreeCoverImage -> openBigImage(mDatabind.includeThree.ivThreeCoverImage)
                mDatabind.includeBar.tvRightMenu -> captureScreenshot("share")
                mDatabind.includeBtn.tvRightBtn -> captureScreenshot("downLoad")
                mDatabind.includeBtn.tvLeftBtn -> captureScreenshot("edit")
                mDatabind.includeBar.ivBack -> finish()
            }
        }
    }

    private fun save(file: File) {
        val dialog = RxDialogDefault(this)
        dialog.setContent("是否同步下载到本地相册?")
        dialog.setLeftBtnContent("否")
        dialog.setRightBtnContent("是")
        dialog.setCancelListener {
            dialog.dismiss()
            upLoadBloodImage(file.path)
        }
        dialog.setSureListener {
            dialog.dismiss()
            upLoadBloodImage(file.path)
            XPermission.create(this, PermissionConstants.STORAGE)
                .callback(object : XPermission.SimpleCallback {
                    override fun onGranted() {
                        ImgUtils.saveBmpToAlbum(this@ActivityPedigreeStyleInfo, file)
                    }

                    override fun onDenied() {}
                })
                .request()
        }
        dialog.setFullScreenWidth()
        dialog.show()
    }

    private fun upLoadBloodImage(mBloodImagePath: String) {
        val map = mapOf("bloodBookId" to mId, "path" to mBloodImagePath)
        val body: RequestBody = Gson().toJson(map).toRequestBody("application/json".toMediaTypeOrNull())
        showLoading(getString(R.string.loading))
        mViewModel.addBloodBookImg(body)
    }

    private fun captureScreenshot(type: String) {
        XXPermissions.with(this)
            .permission(Permission.READ_MEDIA_IMAGES)
            .permission(Permission.READ_MEDIA_VIDEO)
            .permission(Permission.READ_MEDIA_AUDIO)
            .permission(Permission.WRITE_EXTERNAL_STORAGE)
            .interceptor(PermissionInterceptor())
            .request { _, allGranted ->
                if (allGranted) {
                    val bitmap = PictureUtil.getBitmapFromView(mDatabind.conStyleBgBloodBook)
                    val imageUri = PictureUtil.saveBitmapToFile(bitmap, this)
                    when (type) {
                        "edit" -> startActivity<ActivityEditInfoStyle>("bitmap" to imageUri.toString(), "id" to mId, "type" to typeGeneration)
                        "share" -> showBottomDialogSharePicture(bitmap)
                        else -> save(ImgUtils.saveBitmapFile(bitmap))
                    }
                } else {
                    showMessage(getString(R.string.insufficient_privileges))
                }
            }
    }

    @SuppressLint("MissingInflatedId")
    private fun showBottomDialogSharePicture(bitmap: Bitmap) {
        val dialogBottom = BottomSharePictureDialog(bitmap)
        dialogBottom.setOnShareClickListener(object : BottomSharePictureDialog.OnClickSharePicture {
            override fun setOnItemClickListener() {
                requestPermission(bitmap)
                dialogBottom.dismiss()
            }
        })
        dialogBottom.show(supportFragmentManager, "FullScreenBottomSheet")
    }

    private fun requestPermission(bitmap: Bitmap) {
        showLoading("准备中...")
        val url = ImgUtils.getRealFilePath(this, ImgUtils.saveAlbum(this, bitmap, Bitmap.CompressFormat.JPEG, 80, false))
        mDatabind.includeBar.tvRightMenu.postDelayed({
            XXPermissions.with(this)
                // 适配分区存储应该这样写
                .permission(Permission.READ_MEDIA_IMAGES)
                .interceptor(PermissionInterceptor())
                .request(OnPermissionCallback { _, allGranted ->
                    if (!allGranted) {
                        RxToast.showToast(getString(R.string.permission_acquisition_failure))
                        dismissLoading()
                        return@OnPermissionCallback
                    }
                    WxShareUtils.sharePicture(this, Constant.WX_APP_ID, url)
                    dismissLoading()
                })
        }, 1000)
    }

    private fun openBigImage(ivImage: AppCompatImageView) {
        OpenImage.with(this)
            .setClickImageView(ivImage)
            .setSrcImageViewScaleType(ImageView.ScaleType.CENTER_CROP, true)
            .setImageUrl(bigImageUrl, MediaType.IMAGE).show()
    }

    @SuppressLint("SetTextI18n")
    private fun echoData(mInfoDetail: BloodBookDetailResponse) {
        bigImageUrl = mInfoDetail.pgImg
        if (mInfoDetail.list.isNotEmpty()) {
            mInfoDetail.list.forEachIndexed { _, editBloodInfoBean ->
                when (typeGeneration) {
                    "three" -> {
                        mDatabind.includeThree.layoutThree.isVisible = true
                        mDatabind.includeFour.layoutFour.isVisible = false
                        mDatabind.includeFourV.layoutFourV.isVisible = false
                        mDatabind.includeFive.layoutFive.isVisible = false
                        ImageLoaderManager.loadRoundImage(this, bigImageUrl, mDatabind.includeThree.ivThreeCoverImage, 8)
                        when (editBloodInfoBean.levelInfo) {
                            "1" -> mAdapter1.updateItem(0, editBloodInfoBean)//主鸽
                            "1-1" -> mAdapter2.updateItem(0, editBloodInfoBean)//父亲
                            "1-2" -> mAdapter2.updateItem(1, editBloodInfoBean)//母亲
                            "1-1-1" -> mAdapter3.updateItem(0, editBloodInfoBean)//祖父
                            "1-1-2" -> mAdapter3.updateItem(1, editBloodInfoBean)//祖母
                            "1-2-1" -> mAdapter3.updateItem(2, editBloodInfoBean)//外祖父
                            "1-2-2" -> mAdapter3.updateItem(3, editBloodInfoBean)//外祖母
                        }
                    }

                    "four" -> {
                        mDatabind.includeThree.layoutThree.isVisible = false
                        mDatabind.includeFour.layoutFour.isVisible = true
                        mDatabind.includeFourV.layoutFourV.isVisible = false
                        mDatabind.includeFive.layoutFive.isVisible = false
                        ImageLoaderManager.loadRoundImage(this, bigImageUrl, mDatabind.includeFour.ivFourCoverImage, 8)
                        when (editBloodInfoBean.levelInfo) {
                            "1" -> mAdapterFour1.updateItem(0, editBloodInfoBean)//主鸽
                            "1-1" -> mAdapterFour2.updateItem(0, editBloodInfoBean)//父亲
                            "1-2" -> mAdapterFour2.updateItem(1, editBloodInfoBean)//母亲
                            "1-1-1" -> mAdapterFour3.updateItem(0, editBloodInfoBean)//祖父
                            "1-1-2" -> mAdapterFour3.updateItem(1, editBloodInfoBean)//祖母
                            "1-2-1" -> mAdapterFour3.updateItem(2, editBloodInfoBean)//外祖父
                            "1-2-2" -> mAdapterFour3.updateItem(3, editBloodInfoBean)//外祖母
                            "1-1-1-1" -> mAdapterFour4.updateItem(0, editBloodInfoBean)//曾祖父
                            "1-1-1-2" -> mAdapterFour4.updateItem(1, editBloodInfoBean)//曾祖母
                            "1-1-2-1" -> mAdapterFour4.updateItem(2, editBloodInfoBean)//曾外祖父
                            "1-1-2-2" -> mAdapterFour4.updateItem(3, editBloodInfoBean)//曾外祖母
                            "1-2-1-1" -> mAdapterFour4.updateItem(4, editBloodInfoBean)//外曾祖父
                            "1-2-1-2" -> mAdapterFour4.updateItem(5, editBloodInfoBean)//外曾祖母
                            "1-2-2-1" -> mAdapterFour4.updateItem(6, editBloodInfoBean)//外曾外祖父
                            "1-2-2-2" -> mAdapterFour4.updateItem(7, editBloodInfoBean)//外曾外祖母
                        }
                    }

                    "fourV" -> {
                        mDatabind.includeThree.layoutThree.isVisible = false
                        mDatabind.includeFour.layoutFour.isVisible = false
                        mDatabind.includeFourV.layoutFourV.isVisible = true
                        mDatabind.includeFive.layoutFive.isVisible = false
                        ImageLoaderManager.loadRoundImage(this, bigImageUrl, mDatabind.includeFourV.ivFourVCoverImage, 8)
                        when (editBloodInfoBean.levelInfo) {
                            "1" -> mAdapterFourV1.updateItem(0, editBloodInfoBean)//主鸽
                            "1-1" -> mAdapterFourV2.updateItem(0, editBloodInfoBean)//父亲
                            "1-2" -> mAdapterFourV2.updateItem(1, editBloodInfoBean)//母亲
                            "1-1-1" -> mAdapterFourV3.updateItem(0, editBloodInfoBean)//祖父
                            "1-1-2" -> mAdapterFourV3.updateItem(1, editBloodInfoBean)//祖母
                            "1-2-1" -> mAdapterFourV3.updateItem(2, editBloodInfoBean)//外祖父
                            "1-2-2" -> mAdapterFourV3.updateItem(3, editBloodInfoBean)//外祖母
                            "1-1-1-1" -> mAdapterFourV4.updateItem(0, editBloodInfoBean)//曾祖父
                            "1-1-1-2" -> mAdapterFourV4.updateItem(4, editBloodInfoBean)//曾祖母
                            "1-1-2-1" -> mAdapterFourV4.updateItem(1, editBloodInfoBean)//曾外祖父
                            "1-1-2-2" -> mAdapterFourV4.updateItem(5, editBloodInfoBean)//曾外祖母
                            "1-2-1-1" -> mAdapterFourV4.updateItem(2, editBloodInfoBean)//外曾祖父
                            "1-2-1-2" -> mAdapterFourV4.updateItem(6, editBloodInfoBean)//外曾祖母
                            "1-2-2-1" -> mAdapterFourV4.updateItem(3, editBloodInfoBean)//外曾外祖父
                            "1-2-2-2" -> mAdapterFourV4.updateItem(7, editBloodInfoBean)//外曾外祖母
                        }
                    }

                    else -> {
                        mDatabind.includeThree.layoutThree.isVisible = false
                        mDatabind.includeFour.layoutFour.isVisible = false
                        mDatabind.includeFourV.layoutFourV.isVisible = false
                        mDatabind.includeFive.layoutFive.isVisible = true
                        ImageLoaderManager.loadRoundImage(this, bigImageUrl, mDatabind.includeFive.ivFiveImageCover, 8)
                        when (editBloodInfoBean.levelInfo) {
                            "1" -> {
                                mAdapterFive1.updateItem(1, editBloodInfoBean)
                                mDatabind.includeFive.tvChiefRingId.text = "主鸽: " + editBloodInfoBean.ringId
                            } //主鸽
                            "1-1" -> mAdapterFive1.updateItem(0, editBloodInfoBean)//父亲
                            "1-2" -> mAdapterFive1.updateItem(2, editBloodInfoBean)//母亲
                            "1-1-1" -> mAdapterFive2.updateItem(0, editBloodInfoBean)//祖父
                            "1-1-2" -> mAdapterFive2.updateItem(1, editBloodInfoBean)//祖母
                            "1-2-1" -> mAdapterFive2.updateItem(2, editBloodInfoBean)//外祖父
                            "1-2-2" -> mAdapterFive2.updateItem(3, editBloodInfoBean)//外祖母
                            "1-1-1-1" -> mAdapterFive3.updateItem(0, editBloodInfoBean)//曾祖父
                            "1-1-1-2" -> mAdapterFive3.updateItem(1, editBloodInfoBean)//曾祖母
                            "1-1-2-1" -> mAdapterFive3.updateItem(2, editBloodInfoBean)//曾外祖父
                            "1-1-2-2" -> mAdapterFive3.updateItem(3, editBloodInfoBean)//曾外祖母
                            "1-2-1-1" -> mAdapterFive3.updateItem(4, editBloodInfoBean)//外曾祖父
                            "1-2-1-2" -> mAdapterFive3.updateItem(5, editBloodInfoBean)//外曾祖母
                            "1-2-2-1" -> mAdapterFive3.updateItem(6, editBloodInfoBean)//外曾外祖父
                            "1-2-2-2" -> mAdapterFive3.updateItem(7, editBloodInfoBean)//外曾外祖母
                            "1-1-1-1-1" -> mAdapterFive4.updateItem(0, editBloodInfoBean)//高祖父
                            "1-1-1-1-2" -> mAdapterFive4.updateItem(1, editBloodInfoBean)//高祖母
                            "1-1-1-2-1" -> mAdapterFive4.updateItem(2, editBloodInfoBean)//高外祖父
                            "1-1-1-2-2" -> mAdapterFive4.updateItem(3, editBloodInfoBean)//高外祖母
                            "1-1-2-1-1" -> mAdapterFive4.updateItem(4, editBloodInfoBean)//曾外曾祖父
                            "1-1-2-1-2" -> mAdapterFive4.updateItem(5, editBloodInfoBean)//曾外曾祖母
                            "1-1-2-2-1" -> mAdapterFive4.updateItem(6, editBloodInfoBean)//曾外曾外祖父
                            "1-1-2-2-2" -> mAdapterFive4.updateItem(7, editBloodInfoBean)//曾外曾外祖母
                            "1-2-1-1-1" -> mAdapterFive4.updateItem(8, editBloodInfoBean)//外高祖父
                            "1-2-1-1-2" -> mAdapterFive4.updateItem(9, editBloodInfoBean)//外高祖母
                            "1-2-1-2-1" -> mAdapterFive4.updateItem(10, editBloodInfoBean)//外高外祖父
                            "1-2-1-2-2" -> mAdapterFive4.updateItem(11, editBloodInfoBean)//外高外祖母
                            "1-2-2-1-1" -> mAdapterFive4.updateItem(12, editBloodInfoBean)//外曾外曾祖父
                            "1-2-2-1-2" -> mAdapterFive4.updateItem(13, editBloodInfoBean)//外曾外曾祖母
                            "1-2-2-2-1" -> mAdapterFive4.updateItem(14, editBloodInfoBean)//外曾外曾外祖父
                            "1-2-2-2-2" -> mAdapterFive4.updateItem(15, editBloodInfoBean)//外曾外曾外祖母
                        }
                    }
                }
            }
        }
    }
}